package com.welsy.authoring.command
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.welsy.authoring.business.*;
	import com.welsy.authoring.model.CourseModelLocator;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	import mx.controls.Alert;
	import mx.collections.ICollectionView;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.utils.ArrayUtil;
	import com.welsy.authoring.vo.CourseComponentsVO;
	
	/**
	  * The course retriving command
	  * @author Welsy.org
	  * @version	$Revision: 1.1 $
	  */
	public class GetCoursesPublishCommand implements ICommand, Responder
	{
	  	public function GetCoursesPublishCommand()
		{	 
		}
	
		/**
		  * Delegate calling chain
		  * @param event The triggering event
		  */
		public function execute( event : CairngormEvent ): void
		{
			if( CourseModelLocator.getInstance().coursesPublish == null )
			{
			    var delegate : GetCoursesPublishDelegate = new GetCoursesPublishDelegate( this );
			    delegate.getCourses();
			}
		}
	
		/**
		  * The server response handler
		  * @param event The server result
		  */
		public function onResult( event : * = null ) : void
		{				
			var courses : ICollectionView = ICollectionView( event );
			var model : CourseModelLocator = CourseModelLocator.getInstance();
	   		
			model.coursesPublish = courses;
		}
	
		/**
		  * The fault handler
		  * Alert the user of the failure
		  * @param event The failure event
		  */
		public function onFault( event : * = null ) : void
		{
			var faultEvent : FaultEvent = FaultEvent( event );
			Alert.show( "Courses could not be retrieved!" );
		}
	}

}